﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Linq.Expressions;
using NUnit.Framework;
using MongoDB.Driver;
using MongoDB.Driver.Builders;
using MongoDB.Bson;
namespace YmtUserAuth.DataImport
{
    [TestFixture]
    public class QueryTest
    {
        [Test]
        public void FindByQuery()
        {
            var query = Query<UserData2>.ElemMatch(e => e.Value, e => e.In(_ => _.Key, new int[] { 383835 }));
            //var query = Query<UserData2>.Where(e => e.Value.Keys.Contains(383835));
            //var query = Query.And(Query.EQ("Value", 383835));
            Console.WriteLine(query.ToString());
            var findResult = MongoRepository<UserData2>.Find(query);
            Console.WriteLine(findResult.ToJson());
        }

        [Test]
        public void FindByLinq()
        {
            var query = Query<UserData2>.In(e => e.Value.Keys.ToArray(), new int[] { 383835 });
            Func<UserData2, bool> exp = e => e.Value[383835] != null;
            var findResult = MongoRepository<UserData2>.Find(exp);
            Console.WriteLine(findResult.ToJson());
        }
        [Test]
        public void FindByLinq2()
        {
            //var query = Query<UserData>.ElemMatch(e => new string[] { "Value" }, e => e.In(_ => new string[] { "userId" }, new object[] { 383835 }));
            var query = Query.EQ("Value.userId", 383835);
            // Func<UserData2, bool> exp = e => e.Value.Values.Contains(
            var findResult = MongoRepository<UserData>.Find(query);
            Console.WriteLine(findResult.ToJson());
        }


    }
}
